<template>
	<view class="logged">
		<image src="../../static/mine/bg.png" mode="widthFix" class="top-bg"></image>
		<view class="user-box box-shadow flex flex-middle">
			<image :src="avatar" mode="widthFix" class="user-icon"></image>
			<view class="user flex-item">{{ user }}</view>
		</view>
		<view class="list b-b">
			<navigator class="flex flex-middle" url="../ranking/ranking">
				<image src="../../static/mine/ranking.png" mode="widthFix" class="icon"></image>
				<view class="flex-item">新闻排行</view>
			</navigator>
			<navigator class="flex flex-middle b-t" url="../revisePassword/revisePassword">
				<image src="../../static/mine/mima.png" mode="widthFix" class="icon"></image>
				<view class="flex-item">修改密码</view>
			</navigator>
			<view class="flex flex-middle b-t" @click="onAPPUpdate">
				<image src="../../static/mine/version.png" mode="widthFix" class="icon"></image>
				<view class="flex-item">版本检测</view>
				<view class="item-right">V{{ version }}</view>
			</view>
			<navigator class="flex flex-middle b-t" url="../about/about">
				<image src="../../static/mine/about.png" mode="widthFix" class="icon"></image>
				<view class="flex-item">关于我们</view>
			</navigator>
			<view class="flex flex-middle b-t" @click="loginOutModal">
				<image src="../../static/mine/exit.png" mode="widthFix" class="icon"></image>
				<view class="flex-item">退出登录</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user:'',
				version:'',
				avatar:'../../static/mine/user.png'
			}
		},		
		onLoad() {
			this.user = this.$$.getStorage("userinfo")
			this.version = this.$$.getStorage("version")
		},
		methods: {
			goto(e){
				var url = e.currentTarget.dataset.url				
				uni.navigateTo({
					url: url,
				});
			},
			loginOutModal(){
				uni.showModal({
					title: '提示',
					content: '确定要退出登录吗？',
					showCancel: true,
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if(res.confirm) {
							this.loginOut()
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			loginOut(){
				this.$$.request({
					url:this.config.logout,
					method:"POST"
				},true,false).then((res)=>{
					console.log(res);
					this.$store.dispatch('getUser','')
					this.$store.dispatch('getLogged',false)
					
					uni.removeStorageSync("userinfo")
					uni.removeStorageSync("token")
					
					uni.reLaunch({
						url:'/pages/login/login'
					})
				})
			},
			onAPPUpdate(e) {
				// #ifdef APP-PLUS
				this.$$.getUpdate(true)
				// #endif
			}
		}
	}
</script>

<style lang="scss" scoped>
.logged {
	position: relative;
}
.top-bg {
	width: 100%;
	margin-bottom: 166upx;
}
.user-box {
	position: absolute;
	top: 154upx;
	right: 30upx;
	left: 30upx;
	padding: 76upx 79upx;
	background-color: $uni-bg-color;
	.user-icon {
		width: 128upx;
		margin-right: 41upx;
	}
	.user {
		font-size: 36upx;
		color: $uni-text-color;
	}
}
.list {
	.flex {
		padding: 0 52upx;
		height: 100upx;
		color: $uni-text-color;
		&::after {
			font-family: iconfont;
			content: '\e657';
			color: $uni-text-color-grey;
		}
		.icon {
			width: 40upx;
			height: 40upx;
			margin-right: 56upx;
		}
		.flex-item {
			font-size: 32upx;
			color: #666;
		}
		.item-right {
			padding-right: 21upx;
			font-size: 32upx;
			color: $uni-text-color-grey;
		}
	}
	.b-t::before {
		left: 151upx;
	}
}
</style>
